import Router from '@koa/router';

import AuthController from './controllers/auth';
import UserController from './controllers/user';

import ClientController from './controllers/client';
import OrderController from './controllers/order';
import DeliveryController from './controllers/delivery';
import SummaryController from './controllers/summary';

const unprotectedRouter = new Router();

// auth 相关的路由
unprotectedRouter.post('/auth/login', AuthController.login);
unprotectedRouter.post('/auth/register', AuthController.register);

const protectedRouter = new Router();

// client 相关的路由
protectedRouter.get('/client/list', ClientController.listClients);
protectedRouter.post('/client/append', ClientController.appendClient);
protectedRouter.get('/client/check/:id', ClientController.checkClient);
protectedRouter.put('/client/update/:id', ClientController.updateClient);
protectedRouter.delete('/client/delete/:id', ClientController.deleteClient);

// order 相关的路由
protectedRouter.get('/order/list', OrderController.listOrders);
protectedRouter.get('/order/check/:id', OrderController.checkOrder);
protectedRouter.post('/order/append/:clientId', OrderController.appendOrder);
protectedRouter.put('/order/update/:id', OrderController.updateOrder);
protectedRouter.put('/order/updateDelivered/:id', OrderController.updateOrderDelivered);
protectedRouter.delete('/order/delete/:id', OrderController.deleteOrder);
protectedRouter.get('/order/list/:clientId', OrderController.listOrdersByClientId);

// delivery 相关的路由
protectedRouter.get('/delivery/list', DeliveryController.listDelivery);
protectedRouter.get('/delivery/check/:id', DeliveryController.checkDelivery);
protectedRouter.post('/delivery/append/:clientId', DeliveryController.appendDelivery);
protectedRouter.put('/delivery/update/:id', DeliveryController.updateDelivery);
protectedRouter.put('/delivery/remove/:id', DeliveryController.removeOrder);
protectedRouter.put('/delivery/add/:id', DeliveryController.AddOrder);
protectedRouter.delete('/delivery/delete/:id', DeliveryController.deleteDelivery);
protectedRouter.get('/delivery/review/:id', DeliveryController.reviewDelivery);
protectedRouter.get('/delivery/unreview/:id', DeliveryController.unreviewDelivery);
protectedRouter.get('/delivery/pay/:id', DeliveryController.payDelivery);
protectedRouter.get('/delivery/unpay/:id', DeliveryController.unPayDelivery);

// summary 相关的路由
protectedRouter.post('/summary', SummaryController.generateSummary);
protectedRouter.put('/summary/pay', SummaryController.paySummary);
protectedRouter.put('/summary/unpay', SummaryController.unPaySummary);
protectedRouter.get('/summary/statistic', SummaryController.statistic);

// users 相关的路由
protectedRouter.get('/users', UserController.listUsers);
protectedRouter.get('/users/:id', UserController.showUserDetail);
protectedRouter.put('/users/:id', UserController.updateUser);
protectedRouter.delete('/users/:id', UserController.deleteUser);

export { protectedRouter, unprotectedRouter };
